package com.libraryinformation.dao;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.libraryinformation.domain.Book;
import com.libraryinformation.domain.Weather;
import com.libraryinformation.domain.WeatherVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;
import java.util.Objects;

@Mapper
@Transactional
public interface WeatherDao extends BaseMapper<Weather> {
    /**
     * 查询所有监控指标信息
     * @return
     */
    @Select("select id,name,value,unit,status,percentage,scope from weather WHERE deleted=0; ")
    List<WeatherVO> getAll();

    /**
     * 更新监控指标是否删除状态
     * @param id
     * @return
     */
    @Update("update weather set deleted = 1 where id = #{id}; ")
    Integer updateByDeleted(Long id);

    /**
     * 更新监控指标状态
     * @param id
     * @return
     */
    @Update("update weather set status = #{status} where id = #{id}; ")
    Integer updateByStatus(Integer status,Long id);

    /**
     * 根据id查询图书
     * @param id
     * @return
     */
    @Select("select id,name,value,unit,status,percentage,scope from weather where id = #{id}; ")
    Weather selectById(Long id);
    @Insert("insert into weather (id, name,value,unit,status,scope,insertTime,deleted) values (#{id}, #{name}, #{value},#{unit}, #{status},#{scope}, #{insertTime}, 0);")
    Integer insertOrUpdateWeather(Weather weather);
    @Select("select id,name,value,unit,status,percentage,scope from weather WHERE deleted=0  ")
    IPage<WeatherVO> selectAllPage(IPage<Weather> weatherPage);
}
